package com.ruoyi.common.utils;

import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;

public class Condition {

	public Condition() {}
	
	public static <T> QueryWrapper<T> getQueryWrapper(T entity) {
        return new QueryWrapper<T>(entity);
    }
	
	public static <T> IPage<T> getPage(T entity){
		PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        return new Page<>(pageNum, pageSize);
	}
	
	public static <T> IPage<T> getPage(Integer pageNum, Integer pageSize){
        return new Page<>(pageNum, pageSize);
	}
	
	public static <T> TableDataInfo getTableDataInfo(List<T> rows, long total){
		TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setRows(rows);
        rspData.setMsg("查询成功");
        rspData.setTotal(total);
        return rspData;
	}
	
}
